<?php
require_once(APPPATH.'libraries/infoobject.php');
require_once(APPPATH.'views/components/page.php');

/**
 * Info controller
 */
class Info extends CI_Controller {
	
	function __construct()
	{
		parent::__construct();
		
		$this->load->model('info_model');
	}
	
	public function index()
	{
		$data['info'] = $this->info_model->getInfo();
		
		if (Page::getInstance()->isAdmin())
			$this->load->view('info_admin_view', $data);
		else
			$this->load->view('info_view', $data);
	}
	
	public function update()
	{
		if (Page::getInstance()->isAdmin())
		{
			$error = ERROR_NONE;
			$id = $this->input->post('infoid');
			$contactinfo = $this->input->post('contactinfo');
			
			$info = new InfoObject($id, $contactinfo);
			
			if ($id < 0)
			{
				// Insert info
				$error = $this->info_model->insertInfo($info);
			}
			else
			{
				$error = $this->info_model->updateInfo($id, $info);
			}
			
			$this->session->set_userdata('error', $error);
			redirect('info');
		}
		else
		{
			redirect(site_url());
		}
	}
}
/* End of file info.php */
/* Location: ./application/controllers/info.php */